{include file="public/head" /}
<title>新闻详情</title>
</head>
<body>
<header class="am-topbar am-topbar-fixed-top wos-header">
    <div class="am-container">
        <h1 class="am-topbar-brand">
            <a href="{:url('index/Index/index')}"><img src="__STATIC__/images/logo.png" alt=""></a>
        </h1>

        {include file="public/nav" /}
    </div>
</header>

<div class="am-g am-container">
    <div class="am-u-sm-12 am-u-md-12 am-u-lg-12">
        <div class="newstitles">
            <h2>{$data['title']}</h2>
            <span><i class="fa fa-user"></i>&nbsp;{$data['publisher']}</span>
            &nbsp;<i class="fa fa-clock-o"></i>&nbsp;{$data['create_time']|date='Y-m-d H:i',###}
            &nbsp;<i class="fa fa-eye"></i>&nbsp;{$data['view_num']}
            &nbsp;<i class="fa fa-commenting-o"></i>&nbsp;{$data['comment_num']}
            &nbsp;<a href="javascript:" onclick="collect({$data['id']})" title="收藏">
            {php}$icon = $collect ? "fa fa-heart" : "fa fa-heart-o";{/php}
                    <i class="{$icon}" id="collect"></i>
                  </a>
        </div>
        <!--新闻内容-->
        <div class="contents">
            <p dir="ltr"><span style="color: rgb(88, 88, 88); font-family: arial, &#39;microsoft yahei&#39;, 宋体; line-height: 28px; text-align: justify; font-size: 16px; background-color: rgb(255, 255, 255);">{$data['content']}</span></p>
            {php}if($data['img']){{/php}
            <img src="__STATIC__/news_imgs/{$data['img']}" class="am-u-sm-12 am-u-md-8">
            {php}}{/php}
        </div>
    </div>
    <div class="am-u-sm-12 am-u-md-12 am-u-lg-12">
        <!-- 评论区 -->
        <div data-am-widget="titlebar" class="am-titlebar am-titlebar-default" style="margin-bottom: 20px">
            <h2 class="am-titlebar-title">评论区</h2>
        </div>
        <!--查询数据库返回的$comment，其中的items表示查询到的记录数-->
        {php} //dump ($comment->items());
        if(!$comment->items()){{/php}
        <h3 style="text-align: center">还没有人发表评论</h3>
        {php}}else{{/php}
        {volist name="comment" id="vo"}
          <div class="am-comments-list am-comments-list-flip">
             <article class="am-comment">
                 <!--评论用户头像-->
                 {php}$src=$vo['avatar']?$vo['avatar']:"avatar.png"{/php}
                 <img src="__STATIC__/avatar/{$src}" onclick="showStaff({$vo['staff_id']})" id="{$vo['staff_id']}" class="am-comment-avatar" width="48" height="48"/>
              <div class="am-comment-main">
                   <header class="am-comment-hd">
                       <div class="am-comment-meta">
                         <a class="am-comment-author">{$vo.staff_name}</a>
                         评论于 <time>{$vo.create_time|date='Y-m-d H:i:s',###}</time>
                       </div>
                   </header>
                   <div class="am-comment-bd">{$vo.comment}</div>
              </div>
             </article>
          </div>
        {/volist}
        <div style="text-align: center">
          <div class="pagination">{$page}</div>
        </div>
        {php}}{/php}
        <!-- 评论区 -->
        <!-- 发表评论 -->
        <div class="am-comments-list am-comments-list-flip">
           <article class="am-comment am-comment-flip am-comment-secondary">
               <!--我的头像-->
               {php}$src=$user['avatar']?$user['avatar']:"avatar.png"{/php}
               <img src="__STATIC__/avatar/{$src}" class="am-comment-avatar" width="48" height="48"/>
               <div class="am-comment-main">
                    <header class="am-comment-hd">
                        <div class="am-comment-meta">请在此输入评论</div>
                    </header>
                    <div class="am-comment-bd">
                        <!-- 未登录不能评论 -->
                        <textarea rows="2" id="text" style="width: 100%" ></textarea>
                        <input type="text" id="newsId" hidden value="{$data['id']}">
                        <input type="text" id="title" hidden value="{$data['title']}">
                    </div>
               </div>
           </article>
        </div>
        <div class="am-u-sm-12 am-u-md-12 am-u-lg-12" style="text-align: center;margin: 10px">
            {php}if($user){{/php}
            <button class="am-btn am-btn-success" id="submit" style="padding:10px 50px">发表评论</button>
            {php}}else{{/php}
            <button type="button" class="am-btn am-btn-danger"  style="padding:10px 50px" disabled>未登录，不能评论</button>
            {php}}{/php}
        </div>
        <!-- 发表评论 -->
    </div>
</div>

<div data-am-widget="gotop" class="am-gotop am-gotop-fixed" >
    <a href="#top" title="回到顶部">
        <span class="am-gotop-title">回到顶部</span>
        <i class="am-gotop-icon am-icon-chevron-up"></i>
    </a>
</div>

{include file="public/footer" /}
</body>
<script>
    //发表评论 ajax
    $("#submit").click(function () {
        var comment = $("#text");
        if (comment.val()==='') {
            layer.msg('评论不能为空',{time:2000});
            comment.focus();
        }else{
            var newsId = $("#newsId").val();
            var title = $("#title").val();
            $.post("/index/news_detail_controller/comment",{
                newsId:newsId,
                title:title,
                comment:comment.val()
            },function (result) {
                layer.msg(result.msg,{time:1500});
                //评论成功刷新页面
                if(result.code===1) setTimeout(function(){
                    window.location.reload();
                },1500);
            },"json");
        }
    });
    //收藏 ajax
    function collect(id) {
        $.post("/index/news_detail_controller/collect",{id:id},function (result) {
            var collect = $("#collect");
             if(result.msg === "添加收藏成功！") {
                 collect.removeClass('fa-heart-o').addClass('fa-heart');
             }
            if(result.msg === "取消收藏成功！") {
                collect.removeClass('fa-heart').addClass('fa-heart-o');
            }
            layer.msg(result.msg,{time:1000});
        },"json");
    }
    //点击头像显示用户信息 ajax
    function showStaff(staffId) {
        $.post("/index/news_detail_controller/showStaff",{id:staffId},function (result) {
            if(result.code===1) {
                var data = result.data;
                //查询返回值拼接成字符串放入layer
                var msg = data['dep'] + "--" + data['job'] +
                    "<br><i class='fa fa-phone fa-lg'></i>&nbsp;" + data['mobile'] +
                    "<br><i class='fa fa-envelope'></i>&nbsp;" + data['email'];
                var tips = layer.tips(msg, "#" + staffId, {time: 30000});
            }else{
                var tips = layer.tips(result.msg, "#" + staffId, {time: 30000});
            }
            //点击空白处，关闭layer.tips
            $('body').click(function () {
                layer.close(tips);
            });
        },"json");
    }
</script>
</html>